<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
	
<mapper namespace="${basePackageName}.dao.${subPackAndclassName}Dao">
	<sql id="where">
		<where>
			<trim>
				
			</trim>
		</where>
	</sql>
	<!-- 新增-->
	<insert id="add" parameterType="${basePackageName}.vo${spotAndSubPack}</#if>}.${className}Vo">
		insert into ${tableName}
		<trim prefix="(" suffix=")" suffixOverrides=",">
		  <#list fieldList as var>
		      <if test="${var[0]} != null">${var[2]},</if>	
		  </#list>
		</trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
		  <#list fieldList as var>
		      <if test="${var[0]} != null ">${r"#{"}${var[0]}${r"}"},</if>		
		  </#list>
		</trim>
	</insert>
	<!-- 删除-->
	<delete id="delete" parameterType="String">
		delete from ${tableName} where ${pKey[0]} = ${r"#{"}${pKey[1]}${r"}"}
	</delete>
	
	<!-- 修改 -->
	<update id="update" parameterType="${basePackageName}.vo.${subPackAndclassName}Vo">
		update ${tableName}
		<trim prefix="set" suffixOverrides=","> 
			<#list fieldList as var>
				<if test="${var[0]} != null ">${var[2]} = ${r"#{"}${var[0]}${r"}"},</if>
			</#list>
		</trim>
	    where ${pKey[0]} = ${r"#{"}${pKey[1]}${r"}"}
	</update>

	<!-- 通过id获取数据 -->
	<select id="getById" parameterType="String" resultType="${basePackageName}.vo.${subPackAndclassName}Vo">
		select * from ${tableName} where ${pKey[0]} = ${r"#{"}${pKey[1]}${r"}"}
	</select>

	<!-- 分页显示列表 -->
	<select id="query" parameterType="HashMap" resultType="${basePackageName}.vo.${subPackAndclassName}Vo">
		select
		<if test="showField != null and showField != ''">${r"${"}showField${r"}"}</if>
		<if test="showField == null or showField == ''">*</if>
		from ${tableName}
		<include refid="where" />
		<if test="orderField != null and orderField !='' ">
			order by ${r"#{"}orderField${r"}"}
			<if test="orderType != null and orderType !='' ">
				${r"#{"}orderType${r"}"}
			</if>
		</if>
		<if test="start != null and showCount != null">
			limit ${r"#{"}start${r"}"}, ${r"#{"}showCount${r"}"}
		</if>
	</select>

	<select id="queryCount" parameterType="HashMap" resultType="int">
		select count(1) from ${tableName}
		<include refid="where" />
	</select>
</mapper>